package df.applet.form;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import javax.swing.JPanel;
import javax.swing.JToolBar;

//import df.bean.db.conn.DBConnection;
import df.bean.obj.util.DialogBox;
import df.bean.obj.util.Variables;

public class DFServerApp extends JFrame {
    JDesktopPane deskPane=new JDesktopPane();
    
    private BorderLayout layoutMain = new BorderLayout();
    private JPanel panelCenter = new JPanel();
    private JMenuBar menuBar = new JMenuBar();
    private JMenu menuFile = new JMenu();
    private JMenuItem menuFileExit = new JMenuItem();
    private JMenu menuHelp = new JMenu();
    private JMenuItem menuHelpAbout = new JMenuItem();
    private JLabel statusBar = new JLabel();
    private JToolBar toolBar = new JToolBar();
    private JButton toolbarCalculatorFrm = new JButton();
    private JButton monthlyCalculator = new JButton();
    private JButton buttonHelp = new JButton();
    private ImageIcon imageOpen = new ImageIcon(DFServerApp.class.getResource("openfile.gif"));
    private ImageIcon imageClose = new ImageIcon(DFServerApp.class.getResource("closefile.gif"));
    private ImageIcon imageHelp = new ImageIcon(DFServerApp.class.getResource("help.gif"));

    private List aArrayCollection;
    private JButton jBtnImportInvoice = new JButton();
    private Variables vv = new Variables();

    @SuppressWarnings("static-access")
    public DFServerApp() {
        try {
            jbInit();
            // DF Calculate Daily
            vv.setUserID("sys");
            vv.setPassword("sys");
            vv.setHospitalCode("00001");
            this.aArrayCollection = new ArrayList();
             
            this.setContentPane(deskPane);
            this.setVisible(true);    
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setExtendedState(this.MAXIMIZED_BOTH);              

        } catch (Exception e) {
            e.printStackTrace();
            DialogBox.ShowInfo("Error DFServer Application");
        }

   }

    public void jbInit() throws Exception {
        this.setJMenuBar( menuBar );
        this.panelCenter.setLayout( null );
        this.getContentPane().setLayout( layoutMain );
        this.setSize( new Dimension(400, 300) );

        this.setTitle( "Doctor Fee Application Server" );
        menuFile.setText( "File" );
        menuFileExit.setText( "Exit" );
        menuFileExit.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { fileExit_ActionPerformed( ae ); } } );
        menuHelp.setText( "Help" );
        menuHelpAbout.setText( "About" );
        menuHelpAbout.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { helpAbout_ActionPerformed( ae ); } } );
        statusBar.setText( "Status :" );
        toolbarCalculatorFrm.setToolTipText( "Open File" );
        toolbarCalculatorFrm.setIcon( imageOpen );
        toolbarCalculatorFrm.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        toolbarCalculatorFrm_actionPerformed(e);
                    }
                });
        monthlyCalculator.setToolTipText( "Close File" );
        monthlyCalculator.setIcon( imageClose );
        monthlyCalculator.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        monthlyCalculator_actionPerformed(e);
                    }
                });
        buttonHelp.setToolTipText( "About" );
        buttonHelp.setIcon( imageHelp );
        buttonHelp.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        bankPaymentMonthly_actionPerformed(e);
                    }
                });
        jBtnImportInvoice.setToolTipText("About");
        jBtnImportInvoice.setIcon(imageHelp);
        jBtnImportInvoice.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jBtnImportInvoice_actionPerformed(e);
                    }
                });
        menuFile.add( menuFileExit );
        menuBar.add( menuFile );
        menuHelp.add( menuHelpAbout );
        menuBar.add( menuHelp );
        this.getContentPane().add( statusBar, BorderLayout.SOUTH );
        toolBar.add( toolbarCalculatorFrm );
        toolBar.add( monthlyCalculator );
        toolBar.add( buttonHelp );
        toolBar.add(jBtnImportInvoice, null);
        this.getContentPane().add(toolBar, BorderLayout.NORTH);
        this.getContentPane().add(panelCenter, BorderLayout.CENTER);
    }

    void fileExit_ActionPerformed(ActionEvent e) {
        System.exit(0);
    }

    void helpAbout_ActionPerformed(ActionEvent e) {
    try {
        //JOptionPane.showMessageDialog(this, new DFServerApp_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE);
//        DialogBox.ShowInfo("start");
        Variables.setHospitalCode("00001");
//        JInternalFrame jj = new TransDailyFrm();
//        JInternalFrame jj = new ImportDataFrm();
        JFrame jj = new TransDailyFrm();
        jj.setVisible(true);
//        jj.show();
//        addDeskPane(jj); 
    } catch (Exception ex) {ex.printStackTrace();}
/*        this.aArrayCollection.add(this.newFrame("pyt.df.frame.CalculatorDailyFrm"));
        this.aArrayCollection.add(this.newFrame("pyt.df.frame.CalculatorMonthlyFrm"));
        this.aArrayCollection.add(this.newFrame("pyt.df.frame.BankPaymentMonthlyFrm"));
        this.aArrayCollection.add(this.newFrame("pyt.df.frame.ImportInvoiceFrm"));
        
        for (int i=0; i<this.aArrayCollection.size(); i++) 
            this.ShowJInternalFrame((CalculatorFrm)this.aArrayCollection.get(i)); */
    }
    
    public static void main(String[] args){
        new DFServerApp();
    }
    
    private void addDeskPane(JInternalFrame jf) {
        deskPane.add(jf);
    }
    
    private void ShowJInternalFrame(JInternalFrame jFrame) {
        try {
//            jFrame.show();
            jFrame.setVisible(true);
        } catch( Exception err ) { 
            err.printStackTrace();
        }
    }
    
    private CalculatorFrm newFrame(String nameFrame) {
        CalculatorFrm frm = null;
        try {
            
            frm = (CalculatorFrm)Class.forName(nameFrame).newInstance();
//            addDeskPane(frm);
        } catch( Exception err ) {
            err.printStackTrace();
        }
        return frm;
    }


    private void toolbarCalculatorFrm_actionPerformed(ActionEvent e) {
//        this.ShowJInternalFrame((CalculatorFrm)this.aArrayCollection.get(0));
    }

    private void monthlyCalculator_actionPerformed(ActionEvent e) {
//        this.ShowJInternalFrame((CalculatorFrm)this.aArrayCollection.get(1));
    }

    private void bankPaymentMonthly_actionPerformed(ActionEvent e) {
//        this.ShowJInternalFrame((CalculatorFrm)this.aArrayCollection.get(2));
    }

    private void jBtnImportInvoice_actionPerformed(ActionEvent e) {
//        this.ShowJInternalFrame((CalculatorFrm)this.aArrayCollection.get(3));
    }
    public void start() {
        
    }

    public void stop() {
    }

    public void destroy() {
       
    }
    static {
        try {
        } catch (Exception e) {
        }
    }
    
}
